//方法一：开辟额外的空间num[(i+k)%n] = nums[i]
class Solution {
    public void rotate(int[] nums, int k) {
        int n = nums.length;
        int [] num = new int [n];
        for(int i=0;i<n;i++) {
            num[(i+k)%n] = nums[i];
        }
        System.arraycopy(num,0,nums,0,n);
    }
}
//方法二：直接逆置原数组
class Solution {
    public void reverse(int[] nums,int start,int end) {
        while(start<end) {
            int tmp = nums[start];
            nums[start] = nums[end];
            nums[end] = tmp;
            start++;
            end--;
        }
    }
    public void rotate(int[] nums, int k) {
        k %= nums.length; //防止k大于数组的长度
        reverse(nums,0,nums.length-1);
        reverse(nums,0,k-1);
        reverse(nums,k,nums.length-1);
    }
}
